<?php
/**
 * 系统分类服务类
 * Created by PhpStorm.
 * User: jungshen
 * Date: 2018/7/24
 * Time: 10:48
 */
namespace app\admin\service;

use think\Db;

class SystemCateService
{
    /**
     * 获取分类列表
     * @param array $where
     * @param string $filed
     * @return array|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function get_cate_list($where=[],$filed='id,title')
    {
        $list=Db::name('SystemCate')->where($where)->order('sort,id')->field($filed)->select();
        return $list;
    }

    /**
     * 根据分类id获取信息
     * @param $id
     * @param null $field
     * @return array|mixed|null|\PDOStatement|string|\think\Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function get_cate_by_id($id,$field=null)
    {
        if(!empty($field)){
            if(strpos($field,',') !==false){
                return Db::name('SystemCate')->where('id',$id)->field($field)->find();
            }else{
                return Db::name('SystemCate')->where('id',$id)->value($field);
            }
        }else{
            return Db::name('SystemCate')->where('id',$id)->find();
        }

    }
}